export default class Song {
  constructor (id, name, singer, url, pic, duration) {
    this.id = id
    this.name = name
    this.singer = singer
    this.url = url
    this.pic = pic
    this.duration = duration
  }
}

export function createNeteaseSong (item) {
  return new Song(
    item.id,
    item.name,
    filterSingerNetease(item.artists),
    `https://v1.itooi.cn/netease/url?id=${item.id}`,
    item.album.picUrl,
    item.duration / 1000
  )
}

function filterSingerNetease (arr) {
  let singerStr = ''
  let isFirst = true
  arr.forEach(item => {
    if (isFirst) {
      singerStr += item.name
    } else {
      singerStr += `/${item.name}`
    }
    isFirst = false
  })
  return singerStr
}

export function createTencentSong (item) {
  return new Song(
    item.mid,
    item.name,
    filterSingerNetease(item.singer),
    `https://v1.itooi.cn/tencent/url?id=${item.mid}`,
    `http://y.gtimg.cn/music/photo_new/T002R90x90M000${item.album.mid}.jpg?max_age=2592000`,
    0
  )
}
